package cn.wildfire.chat.app.extendsion.classes;

import android.content.Context;

import java.util.ArrayList;
import java.util.HashMap;

import cn.wildfire.chat.app.extendsion.https.OkHttpRequest;
import cn.wildfire.chat.app.extendsion.https.ReqCallBack;
import cn.wildfire.chat.app.extendsion.https.ServerUrlClient;
import cn.wildfirechat.model.GroupInfo;

/**
 * Create by HEKE, 2019/8/25 17:58
 * TODO 设置群组组员VIP权限
 */
public class VIPSetRequest {

    private Context context;
    private GroupInfo groupInfo;
    private ArrayList<String> userList;
    private int type;
    private OnVipSetResultListener onVipSetResultListener;

    public VIPSetRequest(Context context, GroupInfo groupInfo, ArrayList<String> userList, int type, OnVipSetResultListener onVipSetResultListener) {
        this.context = context;
        this.groupInfo = groupInfo;
        this.userList = userList;
        this.type = type;
        this.onVipSetResultListener = onVipSetResultListener;
        req();
    }

    private void req() {
        try {
            HashMap<String, Object> params = new HashMap<>();
            params.put("gid", groupInfo.target);
            params.put("type", "" + type);
            params.put("userList", userList);
            OkHttpRequest.getNewInstance(context).requestAsynJsonObject(ServerUrlClient.SET_VIP, params, new ReqCallBack<String>() {
                @Override
                public void onReqSuccess(String result) {
                    if (onVipSetResultListener != null) {
                        onVipSetResultListener.result(result, true);
                    }
                }

                @Override
                public void onReqFailed(String errorMsg) {
                    if (onVipSetResultListener != null) {
                        onVipSetResultListener.result(errorMsg, false);
                    }
                }
            }).request();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Create by HEKE, 2019/8/25 18:19
     * TODO VIP设置回调结果接口
     */
    public interface OnVipSetResultListener {
        void result(String ret, boolean success);
    }

}
